
Imports System.Data
Partial Class Admin_frmModifySupplier
    Inherits System.Web.UI.Page
    Dim VarSupplierId As String
    Dim _CityVO As New CityVo
    Dim _BO As New Bo
    Dim _StateVO As New StateVo
    Dim _CountryVO As New CountryVo
    Dim _SupplierVo As New SupplierVO
    Dim _EmployeeId As String

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Try
            SetData()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Session("EmpId") = _EmployeeId
    End Sub
    Public Sub ClearAll()
        txtAddress.Text = ""
        txtZipcode.Text = ""
        txtEmailId.Text = ""
        txtPhoneNumber.Text = ""
        txtMobileNumber.Text = ""
        MsgBox("Supplier Modified")
    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _EmployeeId = Session("EmpId")
        If _EmployeeId = "" Then
            Response.Redirect("frmLogin.aspx")
        End If
        VarSupplierId = Request.QueryString("SupplierId")
        If Not IsPostBack Then
            CountryData()
            StateData()
            CityData()
        End If
        If VarSupplierId = "" Then
            Response.Redirect("")
        Else
            If Not IsPostBack Then
                getSupplierData()
            End If
        End If
    End Sub
    Sub getSupplierData()
        Dim dt As New DataTable
        dt = _BO.getSupplierById(VarSupplierId)
        lblSupplierId.Text = VarSupplierId
        txtSupplierName.Text = dt.Rows(0).Item("SupplierName").ToString
        ddlCountry.SelectedValue = dt.Rows(0).Item("Country").ToString
        Call StateData()
        ddlState.SelectedValue = dt.Rows(0).Item("State").ToString
        Call CityData()
        ddlCity.SelectedValue = dt.Rows(0).Item("City").ToString
        txtAddress.Text = dt.Rows(0).Item("Address").ToString
        txtPhoneNumber.Text = dt.Rows(0).Item("PhoneNumber").ToString
        txtEmailId.Text = dt.Rows(0).Item("EmailId").ToString
        txtMobileNumber.Text = dt.Rows(0).Item("MobileNumber").ToString
        txtZipcode.Text = dt.Rows(0).Item("Zipcode").ToString
    End Sub
    Public Sub CountryData()
        Dim dtCountry As DataTable
        dtCountry = _BO.getcountry()
        ddlCountry.DataSource = dtCountry
        ddlCountry.DataValueField = dtCountry.Columns(0).ToString
        ddlCountry.DataTextField = dtCountry.Columns(1).ToString
        ddlCountry.DataBind()
    End Sub
    Sub StateData()
        Dim dtState As DataTable
        dtState = _BO.getstate(ddlCountry.Text)
        ddlState.DataSource = dtState
        ddlState.DataValueField = dtState.Columns(1).ToString
        ddlState.DataTextField = dtState.Columns(2).ToString
        ddlState.DataBind()
    End Sub
    Sub CityData()
        Dim dtCity As DataTable
        dtCity = _BO.getCity(ddlState.SelectedValue)
        ddlCity.DataSource = dtCity
        ddlCity.DataValueField = dtCity.Columns(2).ToString
        ddlCity.DataTextField = dtCity.Columns(3).ToString
        ddlCity.DataBind()
    End Sub
    Protected Sub ddlCountry_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlCountry.SelectedIndexChanged
        StateData()
        CityData()
    End Sub
    Protected Sub ddlState_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlState.SelectedIndexChanged
        CityData()
    End Sub
    Sub SetData()
        _SupplierVo.SupplierId = VarSupplierId
        _SupplierVo.SupplierName = txtSupplierName.Text
        _SupplierVo.Address = txtAddress.Text
        _SupplierVo.Country = ddlCountry.SelectedValue.ToString
        _SupplierVo.State = ddlState.SelectedValue.ToString
        _SupplierVo.City = ddlCity.SelectedValue.ToString
        _SupplierVo.MobileNumber = txtMobileNumber.Text
        _SupplierVo.PhoneNumber = txtPhoneNumber.Text
        _SupplierVo.EmailId = txtEmailId.Text
        _SupplierVo.Zipcode = txtZipcode.Text
        _BO.ModifySupplier(_SupplierVo)
       
        MsgBox("Supplier Updated")
        Response.Redirect("frmTabSupplier.aspx", False)
    End Sub
   
    Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReset.Click
        txtAddress.Text = ""
        txtZipcode.Text = ""
        txtEmailId.Text = ""
        txtPhoneNumber.Text = ""
        txtMobileNumber.Text = ""
    End Sub
End Class
